/*
filter.c
offer kinds of filter function
designed by lunanting

-----------------------
2020-09-14 09:32:24
create file
-----------------------
*/
#include "filter.h"
#include "stdio.h"
#include "string.h"


/***************************************filter**************************************/
/*
mean filter
均值滤波
param:
    obj:filter object
    data:filter data
return:

*/
float xp_filter_mean(FiLTER_mean *obj,float data){
    double d=0.0;
    
    if(obj->init==0){
        memset(obj,0,sizeof(FiLTER_mean));
        obj->init=1;
        obj->foot=0;
    }
    obj->value=data;
    obj->data[obj->foot++]=data;
    if(obj->foot==10)obj->foot=0;
    for(int i=0;i<obj->init;i++){
        d=d+obj->data[i];
    }
    obj->result=(float)(d/obj->init);
    if(obj->init<10){
        obj->init++;
    }
    return obj->result;
}

/***********************************assist function******************************/


//end of the file
